#include <vector>
#include <SFML/Network.hpp>
#include "ServerPlayer.hpp"

#include "server.hpp"

using namespace std;

void RemoveFromVector(sf::IPAddress& Ip, vector<class ServerPlayer>& clients)
{
    for(vector<class ServerPlayer>::iterator iter = clients.begin(); iter != clients.end(); ++iter)
    {
        if(iter->Ip == Ip)
        {
            clients.erase(iter);
            return;
        }
    }
}

void broadcast(sf::SocketUDP& Socket, sf::Packet& Packet, vector<class ServerPlayer>& clients)
{
    for(vector<class ServerPlayer>::iterator iter = clients.begin(); iter != clients.end(); ++iter)
    {
        Socket.Send(Packet,iter->Ip,iter->Port);
    }
}

ServerPlayer& GetServerPlayerByIP(sf::IPAddress& Ip, vector<class ServerPlayer>& clients)
{
    for(vector<class ServerPlayer>::iterator iter = clients.begin(); iter != clients.end(); ++iter)
    {
        if(iter->Ip == Ip)
        {
            return *iter;
        }
    }
    throw "No such client";
}
